VAR
 a:array[0..11312] of int64;
 k,i,n:integer;

BEGIN
 readln(n,k);
 a[0]:=1;
 a[1]:=k-1;

 for i:=2 to n do a[i]:=(k-1)*(a[i-1]+a[i-2]);
 writeln(a[n]);

END.